package com.xxl.job.feign;

import com.xxl.job.xxljob.domain.XxlJobTokenInfo;
import feign.RequestInterceptor;
import feign.RequestTemplate;

import java.util.Objects;

/**
 * @author Tang
 * @classname TokenRequestInterceptor
 * @description [  ]
 * @date 2023/4/6 13:00
 */
public class TokenRequestInterceptor implements RequestInterceptor {

    private static final String XXL_JOB_LOGIN_IDENTITY = "XXL_JOB_LOGIN_IDENTITY=%s";

    @Override
    public void apply(RequestTemplate requestTemplate) {
        final String token = XxlJobTokenInfo.getInstance().getToken();
        if (Objects.nonNull(token)) {
            requestTemplate.header("Cookie",String.format(XXL_JOB_LOGIN_IDENTITY,token));
        }
    }

}
